package com.zhou.base.components.bs.common.util;

import com.zhou.base.components.bs.common.util.pwd.CharacterData;
import com.zhou.base.components.bs.common.util.pwd.CharacterRule;
import com.zhou.base.components.bs.common.util.pwd.EnglishCharacterData;
import com.zhou.base.components.bs.common.util.pwd.PasswordGenerator;

import java.util.Arrays;
import java.util.List;

/**
 * @author xianfeng
 * @date 2023/9/20 17:15
 */
public class PwdUtils {

    private static PasswordGenerator generator;
    private static List<CharacterRule> characterRuleList;

    static {
        characterRuleList = Arrays.asList(
                new CharacterRule(EnglishCharacterData.LowerCase, 1),
                new CharacterRule(EnglishCharacterData.UpperCase, 1),
                new CharacterRule(EnglishCharacterData.Digit, 1),
                // 至少1个自定义中文字符集合字符
                new CharacterRule(new CharacterData() {
                    @Override
                    public String getErrorCode() {
                        return "任意指定的结合测试";
                    }

                    @Override
                    public String getCharacters() {
//                        return "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
                        return "!#$%&*+-._~";
                    }
                }, 1)
        );
        generator = new PasswordGenerator();
    }

    public static String generatePassword(int length) {
        String pwd = generator.generatePassword(length, characterRuleList);
        return pwd;
    }

    public static void main(String[] args) {
        System.out.println(generatePassword(8));
    }

}
